// 1.引入mongoose模块
const mongoose = require('mongoose');

// 2.创建文章集合规则
const articleSchema = new mongoose.Schema({
    title: {
        type: String,
        maxlength: 20,
        minlength: 1,
        required: [true, '请填写文章标题']
    },
    author: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        required: [true, '请传递作者']
    },
    publishDate: {
        type: Date,
        default: Date.now
    },
    cover: {
        type: String,
        default: null
    },
    content: {
        type: String
    },
    likes: {
        type: Number,
        default: 0
    },
    visits: {
        type: Number,
        default: 0
    },
    catagories: {
        type: String,
        default: 'other'
    },
    tags: {
        type: String,
    },
    isTop: {
        type: Boolean,
        default: false
    }
});

// 3.根据规则创建集合
const Article = mongoose.model('Article', articleSchema);
async function createArticle() {
    const article = await Article.create({
        title: 'siuming叻叻猪',
        author: '600d774f888d1e10e4f4bebd',
        cover: 'test',
        content: '我来在改一次还要改的特别的长长',
        likes: 40,
        visits: 0,
        catagories: '情感天地',
        tags: '吹捧,练习'
    })
}

// createArticle()

// 4.将集合做为模块成员进行导出
module.exports = {
    Article
}